#ifndef BITBOARD_H
#define BITBOARD_H

#include <stdint.h>
#include <stdio.h>

//#define MIN(a,b) ((a) < (b) ? (a) : (b))
//#define MAX(a,b) ((a) > (b) ? (a) : (b))
//#define ABS(a) ((a) < 0 ? -(a) : (a))

#define COORD(s) ((s)[0]-'a' + (((s)[1]-'1')<<3))
#define C2N(r,f) (((r)<<3) + (f))

#define BITSET(n,b) ((n) | (bitboard)1 << (b))
#define BITCLEAR(n,b) ((n) & ~((bitboard)1 << (b)))
#define BIT(n,b) ((n) & (bitboard)1 << (b))

#define SLIDER(p) ((p) & 4)
#define ROOK_MOVER(p) (SLIDER(p) && ((p) & 2))
#define BISHOP_MOVER(p) (SLIDER(p) && ((p) & 1))

#define PAWN 1
#define KNIGHT 2
#define KING 3
#define BISHOP 5
#define ROOK 6
#define QUEEN 7


typedef uint64_t bitboard;

#define WHITE 0
#define BLACK 1

typedef struct {
	bitboard all;
	bitboard pawns;
	bitboard pawn_shadow;
	bitboard rooks;
	bitboard knights;
	bitboard bishops;
	bitboard queens;
	bitboard king;
} bitboard_set;

typedef struct {
	bitboard all_pieces;
	bitboard all_pieces_rl90;
	bitboard all_pieces_rl45;
	bitboard all_pieces_rr45;
	bitboard_set color[2];

	int kscastle[2];
	int qscastle[2];
} board_t;


/*
int first_one(int x, int s);
int last_one(int x);
int last_one_64(bitboard x);

uint8_t get_rank_contents(bitboard b, int c);
uint8_t get_file_contents(bitboard b, int c);
uint8_t get_diag_contents(bitboard b, int c, int *map);

bitboard get_piece_board(board_t *b, int color, int piece);
bitboard *get_piece_board_p(board_t *b, int color, int piece);
int get_piece_color(board_t *b, int sq);
int get_piece_type(board_t *b, int sq, int color);
*/

void display_bitboard(FILE *of, bitboard b);
void print_board(FILE *of, board_t *b);

#include "bitboard_inline.h"

#endif

